/*
 * AbmPaciente.java
 *
 * Created on 07/06/2011, 20:45:01
 */
package raccoon.interfaces;

import com.google.common.base.Strings;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.ListModel;
import raccoon.dominio.ObraSocial;
import raccoon.dominio.Paciente;

/**
 *
 * @author Nicolas
 */
public class AbmPaciente extends javax.swing.JDialog {

    /** Creates new form AbmPaciente */
    public AbmPaciente(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        this.estadoInicialComponentes();
    }

    // <editor-fold defaultstate="collapsed" desc="Utilidades">   
    /**
     * Visibilidad inicial de los componentes de la interfaz
     */
    public final void estadoInicialComponentes() {
        this.btnNuevo.setEnabled(true);
        this.btnEditar.setEnabled(false);
        this.btnEliminar.setEnabled(false);
        this.setEnabledPanelPaciente(false);
    }
    
    /**
     * Blanquea todos los campos del formulario de Paciente.
     */
    public void limpiarPanelPaciente(){
        this.txtApellido.setText("");
        this.txtCalle.setText("");
        this.txtDepto.setText("");
        this.dtpFechaNac.setDate(new Date());
        this.txtNombre.setText("");
        this.txtNroDocumento.setText("");
        this.txtNroDomicilio.setText("");
        this.cmbObraSocial.setSelectedIndex(-1);
        this.txtPiso.setText("");
    }
    
    /**
     * <code>SetEnabled(b)</code> a todos los elementos del formulario de Paciente.
     * @param b
     */
    public void setEnabledPanelPaciente(Boolean b){
        this.txtApellido.setEnabled(b);
        this.txtCalle.setEnabled(b);
        this.txtDepto.setEnabled(b);
        this.dtpFechaNac.setEnabled(b);
        this.txtNombre.setEnabled(b);
        this.txtNroDocumento.setEnabled(b);
        this.txtNroDomicilio.setEnabled(b);
        this.cmbObraSocial.setEnabled(b);
        this.txtPiso.setEnabled(b);
        this.btnCancelar.setEnabled(b);
        this.btnGuardar.setEnabled(b);
    }
    // </editor-fold>

    /**
     * Carga en el Jlist una lista de pacientes.
     * @param lista ArrayList<Paciente> Lista a cargar.
     */
    public void cargarListaPacientes(ArrayList<Paciente> lista){
        JList jList=new JList(lista.toArray());
        this.lstPacientes.setModel(jList.getModel());
    }

    /**
     * Carga un paciente en los campos del panel de paciente.
     * @param paciente
     */
    public void setPaciente(Paciente paciente){
        this.txtApellido.setText(paciente.getApellido());
        this.txtCalle.setText(paciente.getDomicilioCalle());
        this.txtDepto.setText(paciente.getDomicilioDepto());
        this.txtNombre.setText(paciente.getNombre());
        this.txtNroDocumento.setText(String.valueOf(paciente.getNroDocumento()));
        this.txtNroDomicilio.setText(String.valueOf(paciente.getDomicilioNumero()));
        //this.txtObraSocial.setText(null);
        this.txtPiso.setText(String.valueOf(paciente.getDomicilioPiso()));
        this.dtpFechaNac.setDate(paciente.getFechaNacimiento());
    }

    /**
    * Crea un paciente a partir de los datos del formulario.
    * @return Paciente
    * @throws IllegalArgumentException Valida campos numericos, fechas y obligatorios.
    */
    public Paciente getPaciente()throws IllegalArgumentException{
        Paciente paciente=new Paciente();
        //TODO si el codigo de las validaciones se utiliza mas de una vez hacer metodo aparte
        //campos obligatorios nombre y apellido
        if(!Strings.isNullOrEmpty(this.txtApellido.getText()) && !Strings.isNullOrEmpty(this.txtNombre.getText())){
            paciente.setApellido(this.txtApellido.getText());
            paciente.setNombre(this.txtNombre.getText());
        }else{
            throw new IllegalArgumentException("El nombre y apellido del paciente deben completarse");
        }

        //campo obligatorio y numerico nroDocumento
        if(!Strings.isNullOrEmpty(this.txtNroDocumento.getText())){
            try{
                    paciente.setNroDocumento(Integer.parseInt(this.txtNroDocumento.getText()));
            }catch(NumberFormatException e){
                throw new IllegalArgumentException("El número de documento del paciente es incorrecto",e);
            }
        }else{
            throw new IllegalArgumentException("El número de documento del paciente debe completarse");
        }
        
        try{//TOD revisar si esta validacion funciona bien cuando se ingresa una fecha invalida
            paciente.setFechaNacimiento((Date)this.dtpFechaNac.getDate());
        }catch(ClassCastException e){
            throw new IllegalArgumentException("La fecha de nacimiento del paciente es invalida.",e);
        }
        paciente.setDomicilioCalle(this.txtCalle.getText());
        try{
            if(!Strings.isNullOrEmpty(this.txtNroDomicilio.getText())){
                paciente.setDomicilioNumero(Integer.parseInt(this.txtNroDomicilio.getText()));
            }
            if(!Strings.isNullOrEmpty(this.txtPiso.getText())){
                paciente.setDomicilioPiso(Integer.parseInt(this.txtPiso.getText()));
            }
        }catch(NumberFormatException e){
            throw new IllegalArgumentException("El número de domicilio o el piso son incorrectos",e);
        }

        paciente.setDomicilioDepto(this.txtDepto.getText());
        
        paciente.setObraSocial((ObraSocial)this.cmbObraSocial.getSelectedItem());

        return paciente;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panel1 = new org.edisoncor.gui.panel.Panel();
        jScrollPane1 = new javax.swing.JScrollPane();
        lstPacientes = new javax.swing.JList();
        txtFiltrarPacienteNombre = new org.edisoncor.gui.textField.TextFieldRectBackground();
        jLabel1 = new javax.swing.JLabel();
        btnNuevo = new org.edisoncor.gui.button.ButtonAction();
        btnEditar = new org.edisoncor.gui.button.ButtonAction();
        btnEliminar = new org.edisoncor.gui.button.ButtonAction();
        buttonTask1 = new org.edisoncor.gui.button.ButtonTask();
        panelFormPaciente = new org.edisoncor.gui.panel.Panel();
        txtNombre = new org.edisoncor.gui.textField.TextFieldRectImage();
        jLabel2 = new javax.swing.JLabel();
        txtApellido = new org.edisoncor.gui.textField.TextFieldRectImage();
        jLabel3 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        txtNroDocumento = new org.edisoncor.gui.textField.TextFieldRectImage();
        txtCalle = new org.edisoncor.gui.textField.TextFieldRectImage();
        jLabel4 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        txtNroDomicilio = new org.edisoncor.gui.textField.TextFieldRectImage();
        jLabel5 = new javax.swing.JLabel();
        txtPiso = new org.edisoncor.gui.textField.TextFieldRectImage();
        jLabel7 = new javax.swing.JLabel();
        txtDepto = new org.edisoncor.gui.textField.TextFieldRectImage();
        jLabel10 = new javax.swing.JLabel();
        btnGuardar = new org.edisoncor.gui.button.ButtonAction();
        btnCancelar = new org.edisoncor.gui.button.ButtonAction();
        lblFechaNac = new javax.swing.JLabel();
        dtpFechaNac = new com.toedter.calendar.JDateChooser();
        cmbObraSocial = new javax.swing.JComboBox();
        jLabel11 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Pacientes");
        setResizable(false);

        panel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255), 2), "Pacientes", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14))); // NOI18N
        panel1.setColorPrimario(new java.awt.Color(89, 188, 235));
        panel1.setColorSecundario(new java.awt.Color(98, 195, 241));
        panel1.setName("panel1"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        lstPacientes.setName("lstPacientes"); // NOI18N
        lstPacientes.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lstPacientesMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(lstPacientes);

        txtFiltrarPacienteNombre.setDescripcion("Busqueda");
        txtFiltrarPacienteNombre.setName("txtFiltrarPacienteNombre"); // NOI18N

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel1.setText("Nombre");
        jLabel1.setName("jLabel1"); // NOI18N

        btnNuevo.setText("Nuevo");
        btnNuevo.setName("btnNuevo"); // NOI18N
        btnNuevo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNuevoActionPerformed(evt);
            }
        });

        btnEditar.setText("Editar");
        btnEditar.setName("btnEditar"); // NOI18N
        btnEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditarActionPerformed(evt);
            }
        });

        btnEliminar.setText("Eliminar");
        btnEliminar.setName("btnEliminar"); // NOI18N

        buttonTask1.setText("Ver Historial");
        buttonTask1.setDefaultCapable(false);
        buttonTask1.setDescription("Tratamientos del Paciente");
        buttonTask1.setName("buttonTask1"); // NOI18N

        panelFormPaciente.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255), 2));
        panelFormPaciente.setColorPrimario(new java.awt.Color(89, 188, 235));
        panelFormPaciente.setColorSecundario(new java.awt.Color(89, 188, 235));
        panelFormPaciente.setName("panelFormPaciente"); // NOI18N

        txtNombre.setName("txtNombre"); // NOI18N

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel2.setText("Nombre");
        jLabel2.setName("jLabel2"); // NOI18N

        txtApellido.setName("txtApellido"); // NOI18N

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel3.setText("Apellido");
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel9.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel9.setText("Nro. Documento");
        jLabel9.setName("jLabel9"); // NOI18N

        txtNroDocumento.setName("txtNroDocumento"); // NOI18N

        txtCalle.setName("txtCalle"); // NOI18N

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel4.setText("Calle");
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel8.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel8.setText("Obra Social");
        jLabel8.setName("jLabel8"); // NOI18N

        txtNroDomicilio.setName("txtNroDomicilio"); // NOI18N

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel5.setText("Nro.");
        jLabel5.setName("jLabel5"); // NOI18N

        txtPiso.setName("txtPiso"); // NOI18N

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel7.setText("Piso");
        jLabel7.setName("jLabel7"); // NOI18N

        txtDepto.setName("txtDepto"); // NOI18N

        jLabel10.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel10.setText("Depto.");
        jLabel10.setName("jLabel10"); // NOI18N

        btnGuardar.setText("Guardar");
        btnGuardar.setName("btnGuardar"); // NOI18N
        btnGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarActionPerformed(evt);
            }
        });

        btnCancelar.setText("Cancelar");
        btnCancelar.setName("btnCancelar"); // NOI18N
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        lblFechaNac.setFont(new java.awt.Font("Tahoma", 0, 12));
        lblFechaNac.setText("Fecha Nac.");
        lblFechaNac.setName("lblFechaNac"); // NOI18N

        dtpFechaNac.setName("dtpFechaNac"); // NOI18N

        cmbObraSocial.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Osecac", "Swiss Medical", "Osde", "Daspu" }));
        cmbObraSocial.setName("cmbObraSocial"); // NOI18N

        javax.swing.GroupLayout panelFormPacienteLayout = new javax.swing.GroupLayout(panelFormPaciente);
        panelFormPaciente.setLayout(panelFormPacienteLayout);
        panelFormPacienteLayout.setHorizontalGroup(
            panelFormPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelFormPacienteLayout.createSequentialGroup()
                .addContainerGap(149, Short.MAX_VALUE)
                .addComponent(btnGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(panelFormPacienteLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelFormPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(panelFormPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel2)
                        .addComponent(jLabel3))
                    .addComponent(jLabel9)
                    .addComponent(jLabel8)
                    .addComponent(jLabel7)
                    .addComponent(jLabel4)
                    .addComponent(lblFechaNac))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelFormPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelFormPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelFormPacienteLayout.createSequentialGroup()
                            .addComponent(txtPiso, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel10)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(txtDepto, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(panelFormPacienteLayout.createSequentialGroup()
                            .addGroup(panelFormPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(txtNroDocumento, javax.swing.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE)
                                .addComponent(txtNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE)
                                .addComponent(txtApellido, javax.swing.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE)
                                .addComponent(txtCalle, javax.swing.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE)
                                .addComponent(dtpFechaNac, javax.swing.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE))
                            .addGap(18, 18, 18)
                            .addComponent(jLabel5)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(txtNroDomicilio, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(cmbObraSocial, javax.swing.GroupLayout.PREFERRED_SIZE, 214, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        panelFormPacienteLayout.setVerticalGroup(
            panelFormPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelFormPacienteLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelFormPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(8, 8, 8)
                .addGroup(panelFormPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3)
                    .addComponent(txtApellido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelFormPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel9)
                    .addGroup(panelFormPacienteLayout.createSequentialGroup()
                        .addComponent(txtNroDocumento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(panelFormPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(dtpFechaNac, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblFechaNac))))
                .addGap(11, 11, 11)
                .addGroup(panelFormPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtCalle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(txtNroDomicilio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelFormPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(txtDepto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtPiso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelFormPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(cmbObraSocial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 51, Short.MAX_VALUE)
                .addGroup(panelFormPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(21, 21, 21))
        );

        jLabel11.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/raccoon/resources/raccoonTransparente.png"))); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N

        javax.swing.GroupLayout panel1Layout = new javax.swing.GroupLayout(panel1);
        panel1.setLayout(panel1Layout);
        panel1Layout.setHorizontalGroup(
            panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtFiltrarPacienteNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE))
                    .addGroup(panel1Layout.createSequentialGroup()
                        .addComponent(btnNuevo, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnEditar, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(buttonTask1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 274, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel11)
                    .addComponent(panelFormPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        panel1Layout.setVerticalGroup(
            panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panel1Layout.createSequentialGroup()
                .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(panel1Layout.createSequentialGroup()
                        .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(txtFiltrarPacienteNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 286, Short.MAX_VALUE))
                    .addComponent(panelFormPaciente, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panel1Layout.createSequentialGroup()
                        .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btnNuevo, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnEditar, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(buttonTask1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel11))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnNuevoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNuevoActionPerformed
        this.setEnabledPanelPaciente(true);
        this.limpiarPanelPaciente();
    }//GEN-LAST:event_btnNuevoActionPerformed

    private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarActionPerformed
        try{
            Paciente paciente=this.getPaciente();
        }catch(IllegalArgumentException e){
            JOptionPane.showMessageDialog(this, e.getMessage(),"Error",JOptionPane.ERROR_MESSAGE);
        }

    }//GEN-LAST:event_btnGuardarActionPerformed

    private void lstPacientesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lstPacientesMouseClicked
        this.setEnabledPanelPaciente(false);
        this.btnEliminar.setEnabled(true);
        this.btnEditar.setEnabled(true);
        int index=lstPacientes.getSelectedIndex();
        ListModel model=lstPacientes.getModel();
        try{
            Paciente pacienteSeleccionado=(Paciente)model.getElementAt(index);
            this.setPaciente(pacienteSeleccionado);
        }catch(ClassCastException e){
            //No hago nada, es cuando hace click en ningun item de la lista
        }
        //TODO validar y llenar los campos con el paciente seleccionado
    }//GEN-LAST:event_lstPacientesMouseClicked

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        this.limpiarPanelPaciente();
        this.setEnabledPanelPaciente(false);
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void btnEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditarActionPerformed
        this.setEnabledPanelPaciente(true);
        this.btnEliminar.setEnabled(false);
        this.btnEditar.setEnabled(false);
    }//GEN-LAST:event_btnEditarActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private org.edisoncor.gui.button.ButtonAction btnCancelar;
    private org.edisoncor.gui.button.ButtonAction btnEditar;
    private org.edisoncor.gui.button.ButtonAction btnEliminar;
    private org.edisoncor.gui.button.ButtonAction btnGuardar;
    private org.edisoncor.gui.button.ButtonAction btnNuevo;
    private org.edisoncor.gui.button.ButtonTask buttonTask1;
    private javax.swing.JComboBox cmbObraSocial;
    private com.toedter.calendar.JDateChooser dtpFechaNac;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblFechaNac;
    private javax.swing.JList lstPacientes;
    private org.edisoncor.gui.panel.Panel panel1;
    private org.edisoncor.gui.panel.Panel panelFormPaciente;
    private org.edisoncor.gui.textField.TextFieldRectImage txtApellido;
    private org.edisoncor.gui.textField.TextFieldRectImage txtCalle;
    private org.edisoncor.gui.textField.TextFieldRectImage txtDepto;
    private org.edisoncor.gui.textField.TextFieldRectBackground txtFiltrarPacienteNombre;
    private org.edisoncor.gui.textField.TextFieldRectImage txtNombre;
    private org.edisoncor.gui.textField.TextFieldRectImage txtNroDocumento;
    private org.edisoncor.gui.textField.TextFieldRectImage txtNroDomicilio;
    private org.edisoncor.gui.textField.TextFieldRectImage txtPiso;
    // End of variables declaration//GEN-END:variables

}
